package com.java.base.exercise.proxy;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * @Author RenPu
 * @Date 2022/7/13 16:08
 * @Version 1.0
 * @Description: cglib动态代理的封装
 **/
public class CglibProxyXF implements MethodInterceptor {


    //初始化CGLIB中Enhancer的对象
    public Object newInstall(Object obj){
       return Enhancer.create(obj.getClass(),this);
    }


    //CGLIB的拦截方法
    @Override
    public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {

        System.out.println("我被CGLIB，代理了 。。。。");
    return   proxy.invokeSuper(obj,args);
    }
}
